package com.ruoyi.system.service.impl.ingredientsServiceImpl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ingredients.PartIngredients;
import com.ruoyi.system.domain.ingredients.PartIngredientsDetail;
import com.ruoyi.system.mapper.ingredients.PartIngredientsDetailMapper;
import com.ruoyi.system.mapper.ingredients.PartIngredientsMapper;
import com.ruoyi.system.service.ingredientsService.IPartIngredientsDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 辅料出入库明细Service业务层处理
 * 
 * @author ljx
 * @date 2020-07-01
 */
@Service
public class PartIngredientsDetailServiceImpl implements IPartIngredientsDetailService
{
    @Resource
    private PartIngredientsDetailMapper partIngredientsDetailMapper;
    @Resource
    private PartIngredientsMapper partIngredientsMapper;

    /**
     * 查询辅料出入库明细
     * 
     * @param id 辅料出入库明细ID
     * @return 辅料出入库明细
     */
    @Override
    public PartIngredientsDetail selectPartIngredientsDetailById(Long id)
    {
        return partIngredientsDetailMapper.selectPartIngredientsDetailById(id);
    }

    /**
     * 查询辅料出入库明细列表
     * 
     * @param partIngredientsDetail 辅料出入库明细
     * @return 辅料出入库明细
     */
    @Override
    public List<PartIngredientsDetail> selectPartIngredientsDetailList(PartIngredientsDetail partIngredientsDetail)
    {
        return partIngredientsDetailMapper.selectPartIngredientsDetailList(partIngredientsDetail);
    }

    /**
     * 新增辅料出入库明细
     * 
     * @param partIngredientsDetail 辅料出入库明细
     * @return 结果
     */
    @Override
    @Transactional
    public int insertPartIngredientsDetail(PartIngredientsDetail partIngredientsDetail)
    {
        partIngredientsDetail.setCreateTime(DateUtils.getNowDate());
        if(partIngredientsDetail.getChangeValue()==null){
            return 0;
        }
        //修改库存
        partIngredientsMapper.updateInventory(partIngredientsDetail);
        return partIngredientsDetailMapper.insertPartIngredientsDetail(partIngredientsDetail);
    }

    /**
     * 修改辅料出入库明细
     * 
     * @param partIngredientsDetail 辅料出入库明细
     * @return 结果
     */
    @Override
    public int updatePartIngredientsDetail(PartIngredientsDetail partIngredientsDetail)
    {
        return partIngredientsDetailMapper.updatePartIngredientsDetail(partIngredientsDetail);
    }

    /**
     * 删除辅料出入库明细对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePartIngredientsDetailByIds(String ids)
    {
        return partIngredientsDetailMapper.deletePartIngredientsDetailByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除辅料出入库明细信息
     * 
     * @param id 辅料出入库明细ID
     * @return 结果
     */
    @Override
    public int deletePartIngredientsDetailById(Long id)
    {
        return partIngredientsDetailMapper.deletePartIngredientsDetailById(id);
    }
}
